<form lay-filter="productionPlanForm" id="productionPlanForm" class="layui-form open-form">
  <div class="open-model">
    <div class="open-auto">
      <div class="layui-form-item table-bor table-auto">
        <table class="layui-table" id="detailProductionPlanTable" lay-filter="detailProductionPlanTable"></table>
      </div>
      <div class="layui-tab" id="productionPlanBox" lay-filter="productionPlanBox" lay-allowclose="true">
        <div class="flex-item">
          <ul class="layui-tab-title br0" id="processNodsTitle"></ul>
        </div>
        <div class="layui-tab-content" id="processNodsContent">
          <div class="layui-row">
            <div class="layui-col-xs3">
              <div class="layui-form-item">
                <label class="layui-form-label w-auto">工序编码</label>
                <div class="layui-input-inline">
                  <input name="processCode" id="processCode" class="layui-input text-red br0" type="text" readonly="readonly" />
                </div>
              </div>
            </div>
            <div class="layui-col-xs3">
              <div class="layui-form-item">
                <label class="layui-form-label w-auto">工位性质</label>
                <div class="layui-input-inline">
                  <input name="workstationNatureName" id="workstationNatureName" class="layui-input text-red br0" type="text" readonly="readonly" />
                </div>
              </div>
            </div>
            <div class="layui-col-xs3">
              <div class="layui-form-item">
                <label class="layui-form-label w-auto">工资定额(元)</label>
                <div class="layui-input-inline">
                  <input name="yield" id="yield" class="layui-input text-red br0" type="text" readonly="readonly" />
                </div>
              </div>
            </div>
            <div class="layui-col-xs12">
              <div class="layui-form-item">
                <label class="layui-form-label w-auto">工序要求：</label>
                <div class="layui-input-inline" style="width: 100%;">
                  <input name="content" id="content" class="layui-input text-red br0" type="text" readonly="readonly" />
                </div>
              </div>
            </div>
          </div>
          <div class="layui-row">
            <!-- <div class="layui-col-md6" style="padding-right: 25px">
              <div class="layui-form-item" style="margin-bottom: 10px">
                <div class="open-details-title">机台排产</div>
              </div>
              <button class="layui-btn  addDeviceProduction" type="button">配置排产设备</button>
              <table class="layui-table" id="deviceProductionTable" lay-filter="deviceProductionTable"></table>
            </div> -->
            <div class="layui-col-md6" style="padding-right: 25px">
              <div class="layui-form-item" style="margin-bottom: 10px">
                <div class="open-details-title" id="workstationType">关联机型</div>
              </div>
              <button class="layui-btn addDevice" id="workstationTypeAdd" type="button">配置设备机型</button>
              <table class="layui-table" id="deviceTable" lay-filter="deviceTable"></table>
            </div>
            <div class="layui-col-md6">
              <div class="layui-form-item" style="margin-bottom: 10px">
                <div class="open-details-title">关联物料</div>
              </div>
              <button class="layui-btn addRelevanceMaterial" type="button">配置排产物料</button>
              <table class="layui-table" id="relevanceMaterialTable" lay-filter="relevanceMaterialTable"></table>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="layui-form-item text-right flex-between" style="justify-content: flex-end">
      <div class="right-btn" style="margin-right: 20px">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        <button class="layui-btn" type="button" id="submitBtn" lay-filter="productionPlanFormSubmit" lay-submit>提交</button>
      </div>
    </div>
  </div>
</form>
<script id="processNodsTitleTemplate1" type="text/html">
  <!-- {{# layui.each(d, function(index, item){ }} -->
  <li lay-id="{{index}}">
    {{item.name }}
    <!--        <i class="layui-icon layui-icon-close layui-unselect layui-tab-close"></i>-->
  </li>
  <!-- {{# }) }} -->
</script>
<!--选择设备-->
<script type="text/html" id="selectProcessDeviceByProcessId">
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
        <!-- 头部操作栏 -->
        <div class="layui-form toolbar">
          <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label w-auto">设备编码</label>
              <div class="layui-input-inline mr0" style="width: 240px;">
                <input name="deviceCode" class="layui-input" type="text" placeholder="请输入设备编码" />
              </div>
            </div>
            <div class="layui-inline">
              <button class="layui-btn icon-btn" lay-filter="selectProcessFormSubSearchLog" lay-submit style="padding: 0 24px;">搜索</button>
              <button id="selectProcessDeviceByProcessIdClose" class="layui-btn icon-btn">确认选择</button>
            </div>
          </div>
        </div>
        <!-- 表格 -->
        <div class="scroll-table-4-5">
          <table class="layui-table" id="selectProcessDeviceByProcessIdTable" lay-filter="selectProcessDeviceByProcessIdTable"></table>
        </div>
      </div>
    </div>
  </div>
</script>
<script type="text/html" id="deviceProductionTableBar">
  <!-- <a class="layui-btn layui-btn-xs" lay-event="detail">明细</a> -->
  <!-- <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a> -->
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="deviceTableBar">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="relevanceMaterialTableBar">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
  layui.use(["form", "table", "admin", "jquery", "laydate", "laytpl", "element", "upload"], async function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var laydate = layui.laydate;
    var laytpl = layui.laytpl;
    var element = layui.element;
    var upload = layui.upload;
    const nowData = { ...parentData };
    console.log(111, nowData.eventName);
    console.log(nowData);

    if (nowData.eventName == "detail") {
      admin.setFormDisable("#productionPlanForm", true);
      $(".addDeviceProduction").hide();
      $("#submitBtn").hide();
      $(".addRelevanceMaterial").hide();
      $(".addDevice").hide();
    }
    let data = nowData.data;
    if (!data.productionPlanQuantity) {
      data.productionPlanQuantity = data.productionQuantity - data.productionPlanHaveQuantity;
    }
    data.productTime = "";
    let processNodsData = [];
    let nodeIndex = 0;
    var detailProductionPlanTable = []; // 计划排产表头部表格
    let xxxList = [];
    table.render({
      elem: "#detailProductionPlanTable",
      data: [data],
      cellMinWidth: 100,
      cols: [
        [
          { field: "code", align: "center", title: "计划编号", width: 150 },
          // { field: "planSourceDesc", align: "center", title: "计划订单类型" },
          { field: "bookCode", align: "center", title: "基准书编号" },
          { field: "customerSkuCode", align: "center", title: "生产物料" },
          { field: "customerSkuSpec", align: "center", title: "物料规格" },
          {
            field: "productTypeName",
            align: "center",
            title: "所属物料系列"
          },
          { field: "productionQuantity", align: "center", title: "生产数量" },
          {
            field: "productionPlanHaveQuantity",
            title: "已排产数量",
            align: "center"
          },
          {
            field: "productionPlanQuantity",
            title: "本次生产数量",
            align: "center",
            templet: admin.setTableInput("productionPlanQuantity", nowData.eventName == "detail", "productionPlanQuantity")
          },
          // { field: "yeild", title: "合格率", align: "center" },
          // { field: "customerName", align: "center", title: "客户信息" },
          {
            field: "shipmentTime",
            align: "center",
            title: "交货时间"
            // templet: admin.setTableInput(
            //   "shipmentTime",
            //   nowData.eventName == "detail"
            // ),
          },
          {
            field: "productTime",
            align: "center",
            title: "计划生产时间",
            templet: admin.setTableInput("productTime", nowData.eventName == "detail", "productTime")
          },
          { field: "statusDesc", align: "center", title: "状态" },
          { field: "createTime", align: "center", title: "创建时间" }
        ]
      ],
      done: function () {}
    });
    admin.tableInputChangeByClass("detailProductionPlanTable", "productionPlanQuantity", function (index, value, tableData, field, tableId) {
      table.reload("relevanceMaterialTable");
    });
    detailProductionPlanTable = table.cache["detailProductionPlanTable"];
    if (nowData.eventName == "detail") {
      const res = await admin.reqPro(
        // "enterprise/echnologyParam/admin/echnologyParam/list",
        "production/productionRecord/admin/productionRecord/detail",
        // "enterprise/echnologyParam/admin/echnologyParam/getEchonlogyInfoBy/" + data.bookId,
        {
          // skuCode: customerSkuCode
          type: nowData.data.planNature,
          productionPlanRecordId: nowData.data.id,
          processId: nowData.data.processId,
          bookId: nowData.data.bookId
        }
      );
      console.log("res", res);
      xxxList = [...res.data];
      xxxList = xxxList.map((v) => {
        v.materialList = v.recordMaterialSkuVos;
        v.processDeviceList = v.productionProcessDevices;
        v.skuList = v.recordMaterialSkuVos;
        v.code = v.resBenchmarkBookEchnology.code;
        v.hoursQuota = v.resBenchmarkBookEchnology.hoursQuota;
        return v;
      });
    } else {
      // let processList = [];
      if (data.planNature == "process") {
        console.log("data1", data);
        // 如果计划有生产工序则隐藏添加按钮
        $("#addProcessNods").hide();
        $(".layui-tab-close").hide();
        const res = await admin.reqPro("enterprise/echnologyParam/admin/echnologyParam/getEchonlogyInfoBy/" + data.bookId);
        let list = res.data.filter((v) => v.id == data.processId);
        xxxList = list;
        //   getProcessOutputAndYield(data.processId, data.processName);
      } else {
        const res = await admin.reqPro("enterprise/echnologyParam/admin/echnologyParam/getEchonlogyInfoBy/" + data.bookId);
        xxxList = res.data;
      }
      xxxList = xxxList.map((item) => {
        item.materialList = item.skuList;
        item.productionPlanId = nowData.data.id;
        item.processId = item.id;
        item.processName = item.name;
        item.pieceRateStatus = "no";
        item.pieceRate = item.hoursQuota;
        item.skuCode = item.skuCode;
        item.processDeviceList = [];

        return item;
      });
    }
    console.log("xxxList", xxxList);
    addTemplate();
    laydate.render({
      elem: ".productTime",
      type: "datetime",
      done: (value) => {
        console.log(value);

        table.cache["detailProductionPlanTable"][0].productTime = value;

        // table.cache["detailProductionPlanTable"][0].productTime=value
        console.log(table.cache["detailProductionPlanTable"]);
      }
    });
    // laydate.render({
    //   elem: "#pTime",
    //   type: "date",
    //   range: true,
    //   done: function (value, date, endDate) {
    //     if (value) {
    //       var dateValue = value.split(" - ");
    //       $("input[name='startCreateTime']").val(dateValue[0] + " 00:00:00");
    //       $("input[name='endCreateTime']").val(dateValue[1] + " 23:59:59");
    //     } else {
    //       $("input[name='startCreateTime']").val("");
    //       $("input[name='endCreateTime']").val("");
    //     }
    //   }
    // });
    // 机台排产表格
    table.render({
      elem: "#deviceProductionTable",
      data: [],
      cellMinWidth: 100,
      page: false,
      cols: [
        [
          { type: "numbers", width: 50, title: "序号" },
          {
            field: "deviceModel",
            align: "center",
            title: "设备型号",
            align: "center"
          },
          {
            field: "deviceCode",
            align: "center",
            title: "设备编码",
            align: "center"
          },
          {
            align: "center",
            toolbar: "#deviceProductionTableBar",
            title: "操作",

            hide: nowData.eventName == "detail"
          }
        ]
      ]
    });
    // 设备机型列表
    table.render({
      elem: "#deviceTable",
      data: [],
      cellMinWidth: 100,
      page: false,
      cols: [
        [
          { type: "numbers", title: "序号", fixed: "left" },
          { field: "id", title: "ID", hide: true },
          {
            field: "deviceName",
            align: "center",
            title: "类型名称",
            fixed: "left"
          },
          { field: "deviceCode", align: "center", title: "类型编号" },
          {
            align: "center",
            toolbar: "#deviceTableBar",
            title: "操作",
            hide: nowData.eventName == "detail"
          }
        ]
      ]
    });

    // 关联物料表格
    table.render({
      elem: "#relevanceMaterialTable",
      data: [],
      cellMinWidth: 100,
      page: false,
      cols: [
        [
          { type: "numbers", width: 40, title: "序号" },
          { field: "skuCode", title: "物料编码", align: "center" },
          { field: "skuName", title: "物料名称", align: "center" },
          {
            field: "quantity",
            title: "单位需求数",
            align: "center",
            templet: admin.setTableInput("quantity", nowData.eventName == "detail", "quantity")
          },
          {
            field: "quantitySum",
            title: "小计数量",
            align: "center",
            templet: function (d) {
              return (d.quantity ?? 0) * (table.cache["detailProductionPlanTable"][0].productionPlanQuantity ?? 0) ?? 0;
            }
          },
          {
            field: "haveQuantity",
            title: "在库数量",
            align: "center"
          },
          // { field: "countQuantity", title: "需求总数量", align: "center", hide: nowData.eventName != "detail" },

          {
            align: "center",
            toolbar: "#relevanceMaterialTableBar",
            title: "操作",
            width: 80,
            hide: nowData.eventName == "detail"
          }
        ]
      ],
      done: () => {
        admin.tableInputChangeByClass("relevanceMaterialTable", "quantity", function (index, value, tableData, field, tableId) {
          let list = xxxList[nodeIndex].skuList;
          let obj = table.cache["detailProductionPlanTable"];
          let productionPlanQuantity = obj[0].productionPlanQuantity ?? 0;
          list[index].quantity = value;
          list[index].quantitySum = value * productionPlanQuantity;
          admin.setTableColHtml(tableId, index, "quantitySum", list[index].quantitySum);

          xxxList[nodeIndex].skuList = list;
        });
      }
    });

    $(".addRelevanceMaterial").click(function () {
      let index = $(".layui-tab-title .layui-this").attr("lay-id");
      let list = table.cache["relevanceMaterialTable"];
      admin.formOpen({
        title: "配置关联物料",
        area: "90%",
        offset: "50px",
        path: "components/purchase/skuTableForm.html",
        success: function () {
          parentData.notInListIds = list.map((v) => v.productDetailId).join(",");
        },
        end: function () {
          if (childData.list && childData.list.length > 0) {
            list = [...list, ...childData.list];

            xxxList[nodeIndex].skuList = list;
            table.reload("relevanceMaterialTable", {
              data: list
            });
          }
        }
      });
    });
    $(".addDevice").click(function () {
      let workstationNature = xxxList[nodeIndex].workstationNature;
      let index = $(".layui-tab-title .layui-this").attr("lay-id");
      let list = table.cache["deviceTable"];
      if (workstationNature == 1) {
        admin.formOpen({
          title: "配置设备机型",
          area: "90%",
          offset: "50px",
          path: "components/device/deviceModel.html",
          success: function () {
            parentData.eventName = "checkbox";
            parentData.where = {
              notInListIds: list.map((v) => v.id).join(",")
            };
          },
          end: function () {
            if (childData.list && childData.list.length > 0) {
              let newList = [...childData.list].map((v) => {
                v.deviceCode = v.modelNo;
                v.deviceName = v.name;
                return v;
              });
              list = [...list, ...newList];
              xxxList[nodeIndex].deviceTypeList = list;
              table.reload("deviceTable", {
                data: list
              });
            }
          }
        });
      } else if (workstationNature == 2) {
        admin.formOpen({
          title: "配置关联工种",
          area: "90%",
          offset: "50px",
          path: "components/product/professionList.html",
          success: function () {
            parentData.eventName = "checkbox";
            parentData.where = {
              notInListIds: list.map((v) => v.id).join(",")
            };
          },
          end: function () {
            if (childData.list && childData.list.length > 0) {
              let newList = [...childData.list].map((v) => {
                v.deviceCode = v.professionCode;
                v.deviceName = v.professionName;
                return v;
              });
              list = [...list, ...newList];
              xxxList[nodeIndex].deviceTypeList = list;
              table.reload("deviceTable", {
                data: list
              });
              console.log(table.cache["deviceTable"]);
            }
          }
        });
      }
    });
    // tab切换改变下标
    element.on("tab(productionPlanBox)", function () {
      nodeIndex = this.getAttribute("lay-id");
      tabClick(nodeIndex);
    });
    tabClick(0);
    function tabClick(index) {
      table.reload("relevanceMaterialTable", {
        data: []
      });
      table.reload("relevanceMaterialTable", {
        data: xxxList[nodeIndex].skuList
      });
      // table.reload("deviceProductionTable", {
      //   data: xxxList[nodeIndex].processDeviceList
      // });
      table.reload("deviceTable", {
        data: []
      });
      table.reload("deviceTable", {
        data: xxxList[nodeIndex].deviceTypeList
      });
      $("#processCode").val(xxxList[index].code);
      $("#yield").val(xxxList[index].salaryQuota);
      $("#content").val(xxxList[index].content ? xxxList[index].content : "暂时无要求");
      $("#workstationNatureName").val(xxxList[index].workstationNatureName);
      console.log(xxxList[index].workstationNature);

      if (xxxList[index].workstationNature == "1") {
        $("#workstationType").html("关联机型");
        $("#workstationTypeAdd").html("配置设备机型");
      } else if (xxxList[index].workstationNature == "2") {
        $("#workstationType").html("关联工种");
        $("#workstationTypeAdd").html("配置工种");
      }
    }

    // 添加排产设备
    $(".addDeviceProduction").click(function () {
      var selectProcessDeviceByProcessId = admin.open({
        type: 1,
        title: "排产设备",
        area: "75%",
        offset: ["100px", "380px"],
        content: $("#selectProcessDeviceByProcessId").html(),
        success: function () {
          form.render("select");
          // 渲染表格
          var selectProcessDeviceByProcessIdTable = table.render({
            elem: "#selectProcessDeviceByProcessIdTable",
            url: config.base + "enterprise/device/admin/device/list",
            page: true,
            cellMinWidth: 100,
            cols: [
              [
                { type: "checkbox" },
                { field: "deviceCode", align: "center", title: "设备编码" },
                { field: "name", align: "center", title: "设备名称" },
                {
                  field: "deviceModelName",
                  align: "center",
                  title: "设备型号"
                },
                { field: "createTime", align: "center", title: "创建时间" }
              ]
            ]
          });

          // 搜索
          form.on("submit(selectProcessFormSubSearchLog)", function (data) {
            selectProcessDeviceByProcessIdTable.reload(
              {
                where: data.field,
                page: { curr: 1 }
              },
              "data"
            );
          });

          // 确认选择
          $("#selectProcessDeviceByProcessIdClose").click(function () {
            let checkStatus = table.checkStatus("selectProcessDeviceByProcessIdTable"); //test即为基础参数id对应的值
            let list = checkStatus.data;
            if (checkStatus.data.length == 0) {
              layer.msg("请选择设备", { icon: 2, time: 1000 });
            } else {
              list = [...xxxList[nodeIndex].processDeviceList, ...list];
              // 去重id
              xxxList[nodeIndex].processDeviceList = list.filter((item, index, self) => {
                return self.findIndex((t) => t.id === item.id) === index;
              });
              tabClick(nodeIndex);
              layer.close(selectProcessDeviceByProcessId);
            }
          });
        }
      });
    });

    // 添加模板
    function addTemplate() {
      $(".isData").show();
      // 加载节点标题
      templateTitle();
      // 加载节点内容
      //   templateContent();
    }

    // 节点标题

    function templateTitle() {
      laytpl(processNodsTitleTemplate1.innerHTML).render(xxxList, function (html) {
        // laytpl(processNodsTitleTemplate1.innerHTML).render(processNodsData, function (html) {

        $("#processNodsTitle").html(html);
        // 删除tab选项卡
        // deleteTemplateTitle();
      });
    }

    table.on("tool(deviceProductionTable)", function (obj) {
      let event = obj.event;
      if (event == "del") {
        // const index = $(obj.tr[0]).data("index");
        let id = obj.data.id;
        let list = xxxList[nodeIndex].processDeviceList;
        list = list.filter((v) => {
          return v["id"] != id;
        });
        xxxList[nodeIndex].processDeviceList = list;
        tabClick(nodeIndex);
      }
    });
    table.on("tool(relevanceMaterialTable)", function (obj) {
      let event = obj.event;
      if (event == "del") {
        // const index = $(obj.tr[0]).data("index");
        let id = obj.data.productDetailId;
        let list = xxxList[nodeIndex].skuList;
        list = list.filter((v) => {
          return v["productDetailId"] != id;
        });
        xxxList[nodeIndex].skuList = list;
        tabClick(nodeIndex);
      }
    });
    table.on("tool(deviceTable)", function (obj) {
      let event = obj.event;
      if (event == "del") {
        let id = obj.data.id;
        let list = xxxList[nodeIndex].deviceTypeList;
        list = list.filter((v) => {
          return v["id"] != id;
        });
        xxxList[nodeIndex].deviceTypeList = list;
        tabClick(nodeIndex);
      }
    });
    // 提交数据
    form.on("submit(productionPlanFormSubmit)", function (d) {
      let headObj = table.cache["detailProductionPlanTable"][0];
      let productionPlanId = headObj.id;
      let productionPlanHaveQuantity = Number(headObj.productionPlanHaveQuantity) + Number(headObj.productionPlanQuantity);
      if (!headObj.productionPlanQuantity) {
        layer.msg("请填写生产数量", { icon: 2 });
        return false;
      }
      let deviceNot = null;
      xxxList.forEach((v) => {
        v.processDeviceList.forEach((v1) => {
          v1.processId = v.processId;
        });
        if (!v.deviceTypeList || v.deviceTypeList.length == 0) {
          deviceNot = v.name;
        }
        v.materialList = v.skuList;
      });
      if (deviceNot) {
        layer.msg("工序" + deviceNot + "未配置设备机型");
        return;
      }
      let formData = {
        productionPlanId: productionPlanId,
        productionPlanQuantity: headObj.productionPlanQuantity,
        productionPlanHaveQuantity: headObj.productionPlanHaveQuantity,
        allProductionPlanQuantity: headObj.productionQuantity,
        productDetailId: headObj.productDetailId,
        skuCode: headObj.customerSkuCode,
        bookId: headObj.bookId,
        orderType: headObj.orderType,
        // predictStartTime: "",
        predictFinishTime: headObj.shipmentTime,
        productTime: headObj.shipmentTime,
        submitProductionPlanForms: xxxList
      };
      console.log(formData);
      // console.log(headObj);

      // return;
      admin.req(
        "production/productionPlan/admin/productionPlan/submitProductionPlan",
        JSON.stringify(formData),
        function (res) {
          layer.closeAll("loading");
          if (res.code == 200) {
            // 提交成功清空缓存数据
            let saveProcessData = config.getTempData("saveProcessData");
            let saveList = [];
            if (saveProcessData != undefined && saveProcessData != "") {
              saveProcessData.forEach((item) => {
                if (item.productionPlanId != productionPlanId) {
                  saveList.push(item);
                }
              });
            }
            config.putTempData("saveProcessData", saveList);
            layer.msg(res.msg, { icon: 1 });
            table.reload("productionPlanTable");
            layer.closeAll();
          } else {
            layer.msg(res.msg, { icon: 2 });
          }
        },
        "POST",
        true,
        "application/json; charset=utf-8"
      );
      return false;
      let deviceFilter = [],
        flag = false;
      if (processNodsData.length == 0) {
        layer.msg("请添加工序", { icon: 2 });
        return false;
      }
      // 循环判断不能提交为空的数据
      console.log("processNodsData11", processNodsData);

      processNodsData.forEach((item, index) => {
        // console.log(table.cache["relevanceMaterialTable" + index]);
        // item.materialList = item.skuList;
        item.materialList = table.cache["relevanceMaterialTable" + index];
        item.skuList = table.cache["relevanceMaterialTable" + index];
        if (item.processDeviceList.length == 0) {
          layer.msg(`${item.title}排产设备不能为空`, { icon: 2 });
          flag = true;
          return false;
        }
        if (item.materialList.length == 0) {
          layer.msg(`${item.title}排产物料不能为空`, { icon: 2 });
          flag = true;
          return false;
        }
        deviceFilter = item.processDeviceList.filter((item) => {
          return item.status == "yes";
        });
        // if (deviceFilter.length == 0) {
        //   layer.msg(`请保存${item.title}的排产设备`, { icon: 2 });
        //   flag = true;
        //   return false;
        // }
      });
      // 控制不能提交为空的数据
      if (flag) {
        return false;
      }
      let productionList = [];
      processNodsData.forEach((item) => {
        // 筛选出有保存过的排产设备
        // let deviceFilter = item.processDeviceList.filter((item) => {
        //   return item.status == "yes";
        // });
        let list = [];
        item.processDeviceList.forEach((ele) => {
          list.push({
            deviceCode: ele.deviceCode,
            deviceModel: ele.deviceModel,
            planProductionQuantity: ele.planProductionQuantity,
            outputQuantity: ele.outputQuantity,
            processId: ele.processId
          });
        });
        // 提交的数组
        productionList.push({
          productionPlanId: item.productionPlanId,
          processId: item.processId,
          processName: item.title,
          pieceRateStatus: item.pieceRateStatus,
          pieceRate: item.pieceRate,
          skuCode: item.skuCode,
          processDeviceList: list,
          materialList: item.materialList,
          skuList: item.skuList
        });
      });
      layer.load(2);
      // let formData = {
      //   productionPlanId: table.cache["detailProductionPlanTable"][0].id,
      //   productionPlanQuantity: table.cache["detailProductionPlanTable"][0].productionPlanQuantity,
      //   productionPlanHaveQuantity: table.cache["detailProductionPlanTable"][0].productionPlanHaveQuantity,
      //   submitProductionPlanForms: productionList
      // };
      // console.log(formData);
      // console.log(table.cache["detailProductionPlanTable"]);

      // // return false;
      // // 提交计划
      // admin.req(
      //   "production/productionPlan/admin/productionPlan/submitProductionPlan",
      //   JSON.stringify(formData),
      //   function (res) {
      //     layer.closeAll("loading");
      //     if (res.code == 200) {
      //       // 提交成功清空缓存数据
      //       let saveProcessData = config.getTempData("saveProcessData");
      //       let saveList = [];
      //       if (saveProcessData != undefined && saveProcessData != "") {
      //         saveProcessData.forEach((item) => {
      //           if (item.productionPlanId != productionPlanId) {
      //             saveList.push(item);
      //           }
      //         });
      //       }
      //       config.putTempData("saveProcessData", saveList);
      //       layer.msg(res.msg, { icon: 1 });
      //       table.reload("productionPlanTable");
      //       layer.closeAll();
      //     } else {
      //       layer.msg(res.msg, { icon: 2 });
      //     }
      //   },
      //   "POST",
      //   true,
      //   "application/json; charset=utf-8"
      // );

      return false;
    });
  });
</script>
